package myexchange

class Player extends User{
	
	static hasMany = [shares:Exchange, cards:Card]
	
	static transients = [ "wealth" ]
	
	String nickname;
	int cash = 100;
	int wealth = cash; 
	List<Card> cards = new ArrayList<Card>()
	 
	String toString(){
		return nickname;
	}
	
	int getWealth(){
		int wealth = cash
		
		def exchangeList = Exchange.findAllByPlayer(this)
		for(Exchange exchange : exchangeList){
			wealth = wealth + exchange.share.price * exchange.quantity
		}
		return wealth
	}
}
